package aerouacmsla.interfazDeUsuario;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Marco
 */
public class PanelBoleto extends javax.swing.JPanel implements Printable{

    private String idBoleto;
    private String origen;
    private String destino;
    private String numeroAsiento;
    private String hora;
    private String fecha;

    public PanelBoleto() {
        initComponents();
    }

    public PanelBoleto(String idBoleto, String origen, String destino, String numeroAsiento, String hora, String fecha) {
        initComponents();
        setIdBoleto(idBoleto);
        setOrigen(origen);
        setDestino(destino);
        setNumeroAsiento(numeroAsiento);
        setHora(hora);
        setFecha(fecha);
        //imprimirBoleto();
    }

    public void imprimirBoleto(){
        try {
            PrinterJob job = PrinterJob.getPrinterJob();
            job.setPrintable(this);
            job.printDialog();
            job.print();
        } catch (PrinterException ex) {
            Logger.getLogger(PanelBoleto.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public String getDestino() {
        return destino;
    }

    public void setDestino(String destino) {
        this.destino = destino;
        labelDestino.setText(getDestino());
    }

    public String getFecha() {
        return fecha;
    }

    public void setFecha(String fecha) {
        this.fecha = fecha;
        labelFecha.setText(getFecha());
    }

    public String getHora() {
        return hora;
    }

    public void setHora(String hora) {
        this.hora = hora;
        labelHora.setText(getHora());
    }

    public String getIdBoleto() {
        return idBoleto;
    }

    public void setIdBoleto(String idBoleto) {
        this.idBoleto = idBoleto;
        labelIdBoleto.setText(getIdBoleto());
    }

    public String getNumeroAsiento() {
        return numeroAsiento;
    }

    public void setNumeroAsiento(String numeroAsiento) {
        this.numeroAsiento = numeroAsiento;
        labelAsiento.setText(getNumeroAsiento());
    }

    public String getOrigen() {
        return origen;
    }

    public void setOrigen(String origen) {
        this.origen = origen;
        labelOrigen.setText(getOrigen());
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        backgroundJPanel1 = new org.neocs.beans.panel.BackgroundJPanel();
        jLabel1 = new javax.swing.JLabel();
        labelIdBoleto = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        labelOrigen = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        labelDestino = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        labelAsiento = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        labelHora = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        labelFecha = new javax.swing.JLabel();

        backgroundJPanel1.setFondoImagenIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/BoletoBackGround.png"))); // NOI18N

        jLabel1.setText("ID Boleto:");

        labelIdBoleto.setText("1");

        jLabel3.setText("Origen:");

        labelOrigen.setText("miOrigen");

        jLabel5.setText("Destino:");

        labelDestino.setText("miDestino");

        jLabel2.setText("Numero de Asiento:");

        labelAsiento.setText("miAsiento");

        jLabel4.setText("Hora del Vuelo:");

        labelHora.setText("miHora");

        jLabel6.setText("Fecha del Vuelo:");

        labelFecha.setText("miFecha");

        javax.swing.GroupLayout backgroundJPanel1Layout = new javax.swing.GroupLayout(backgroundJPanel1);
        backgroundJPanel1.setLayout(backgroundJPanel1Layout);
        backgroundJPanel1Layout.setHorizontalGroup(
            backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backgroundJPanel1Layout.createSequentialGroup()
                .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(backgroundJPanel1Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel4)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(labelOrigen)
                            .addComponent(labelDestino)
                            .addComponent(labelAsiento)
                            .addComponent(labelHora)
                            .addComponent(labelFecha)))
                    .addGroup(backgroundJPanel1Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(labelIdBoleto)))
                .addContainerGap(123, Short.MAX_VALUE))
        );
        backgroundJPanel1Layout.setVerticalGroup(
            backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backgroundJPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(labelIdBoleto))
                .addGap(18, 18, 18)
                .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(labelOrigen))
                .addGap(18, 18, 18)
                .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(labelDestino))
                .addGap(18, 18, 18)
                .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(labelAsiento))
                .addGap(18, 18, 18)
                .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(labelHora))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(backgroundJPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(labelFecha))
                .addGap(28, 28, 28))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundJPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(backgroundJPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.neocs.beans.panel.BackgroundJPanel backgroundJPanel1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel labelAsiento;
    private javax.swing.JLabel labelDestino;
    private javax.swing.JLabel labelFecha;
    private javax.swing.JLabel labelHora;
    private javax.swing.JLabel labelIdBoleto;
    private javax.swing.JLabel labelOrigen;
    // End of variables declaration//GEN-END:variables

    public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException {
        if (pageIndex > 0) { /* We have only one page, and 'page' is zero-based */
            return NO_SUCH_PAGE;
        }

        Graphics2D g2d = (Graphics2D)graphics;
        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());

        this.printAll(graphics);

        return PAGE_EXISTS;
    }

}
